#[cfg(feature = "ssr")]
mod mysql_db;
#[cfg(feature = "ssr")]
mod callback;
#[cfg(feature = "ssr")]
mod binary_file;
#[cfg(feature = "ssr")]
pub use mysql_db::*;
#[cfg(feature = "ssr")]
pub use callback::Callback;
#[cfg(feature = "ssr")]
pub use binary_file::*;

#[cfg(feature = "ssr")]
use crate::prelude::{get_app_config, get_ch_pool};

#[cfg(feature = "ssr")]
pub async fn del_rept_tmp_talbe_in_ch(rept_names: &[String]) ->  anyhow::Result<u32> {
    let mut count=0u32;
    let conf=get_app_config();
    let mut client = get_ch_pool().get_handle().await?;
    for rept_name in rept_names {
        let sql = format!("select name from system.tables c where database ='{}' and name like 'tmp_{rept_name}_%'", conf.clickhouse.database);
        let block=client.query(sql).fetch_all().await?;
        for row in block.rows() {
            let table_name: String = row.get("name")?;
            let sql = format!("drop table if exists `{}`", table_name);
            client.execute(sql).await?;
            count += 1;
        }
    }
    Ok(count)
}
